home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / cp1.zip / WHARC.C < prev    next >
C/C++ Source or Header  |  1993-06-10  |  5KB  |  156 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville, MI
  3. Date: 06-06-93 (23:07)             Number: 253
  4. From: DAVID GERSIC                 Refer#: 141
  5.   To: MICHAEL INGRAM                Recvd: NO  
  6. Subj: Re: Arcivers "ID" strings      Conf: (36) C Language
  7. ---------------------------------------------------------------------------
  8. /* Quoting MICHAEL INGRAM on 06-03-93  01:45... */
  9.  
  10.  MI> I am messing around with some different arciver programs on the PC,
  11.  MI> and was wondering if anyone out there had any specs for "ID" strings
  12.  MI> of certian arciver programs.  I beleive PKzip uses "PK" as the first
  13.  MI> two characters in the file.  I am looking for the "ID" strings for:
  14.  
  15. Bob Stout just posted this a few days ago, but:
  16.  
  17. #include <stdio.h>
  18. #include <string.h>
  19.  
  20. #define TEST
  21.  
  22. int WhichArc(char *pName);
  23.  
  24. #ifdef TEST
  25.  
  26. int
  27. main(int argc,char *argv[])
  28. {
  29.     char *arc_types[]={"UNKNOWN",
  30.                        "ARC",
  31.                        "ZOO",
  32.                        "ARJ",
  33.                        "LHARC",
  34.                        "LHA",
  35.                        "ZIP",
  36.                        "PAK",
  37.                        "PAK",
  38.                        "ARC6",
  39.                        "SFXARC",
  40.                        "SFXARJ",
  41.                        "SFXLHARC",
  42.                        "SFXLHA",
  43.                        "SFXZIP",
  44.                        "SFXARC6",
  45.                        "SFXPAK",
  46.                        "EXE"};
  47.  
  48.     printf("Archive type is %s\n",arc_types[WhichArc(argv[1])]);
  49.     return(0);
  50. }
  51.  
  52. #endif
  53.  
  54. /* --------------------------------------------------------------------
  55.    Module:     WHICHARC.C
  56.    Subject:    tries to determine the archiver used to compress files
  57.    Author:     Heinz Ozwirk
  58.                free for all participants of the C_ECHO
  59.    Started:    28.09.1991   13:35:57
  60.    Modified:   13.10.1991   14:15:57
  61.    Modified:   5 January, 1992 11:50am by David Gersic
  62.                    Added return codes for self extracting archive files.
  63.    Modified:   16 January, 1992, 4:15pm by David Gersic
  64.                    Added Pak and ARC ver. 6 with information from Richard
  65.                    Vanhouten @1:272/38. I'm not sure that this code works
  66.                    perfectly for those formats, as his message seems to
  67.                    indicate that the entire archive has to be scanned for
  68.                    headers to check before the type can be perfectly
  69.                    determined. It seems to work for test archives produced
  70.                    here, but may not work for all archives.
  71.    --------------------------------------------------------------------
  72.    Prototype:  int WhichArc(char *pName)
  73.       pName    address of full path name of file to examine
  74.       Result   -1:      file not found
  75.                UNKNOWN: unknown packer
  76.                ARC:     ARC or PKARC
  77.                ARJ:     ARJ
  78.                LHA:     LHARC or LHA
  79.                ZIP:     PKZIP
  80.                ZOO:     Zoo
  81.                PAK:     Pak
  82.                ARC6:    ARC ver. 6 or higher
  83.                SFXARC:  Self Extracting PKARC
  84.                SFXARJ:  Self Extracting ARJ
  85.                SFXLHARC:Self Extracting LHARC
  86.                SFXLHA:  Self Extracting LHA
  87.                SFXZIP:  Self Extracting ZIP
  88.                SFXPAK:  Self Extracting Pak
  89.                SFXARC6: Self Extracting ARC ver. 6 or higher
  90.                EXE:     MS DOS executable of unknown type
  91.  
  92.    LHARC/LHA
  93.       No archive header. WhichArc examines the checksum of the first
  94.       file header. If the checksum is valid and if the string -lh?-
  95.       is found, LHA or LHARC is assumed.
  96.  
  97.    ARJ
  98.       If a file starts with 0x60, 0xEA, ARJ is assumed.
  99.  
  100.    ZIP
  101.       If the file begins with "PK", PKZIP is assumed.
  102.  
  103.    ZOO
  104.       Zoo'ed archives always start with "ZOO x.xx Archive". WhichArc
  105.       only looks for "ZOO".
  106.  
  107.    ARC
  108.       No header. Files starting with 0x1A are assumed to be ARCed.
  109.  
  110.    PAK
  111.       Similar to ARC files, but if the second byte of the header is 0x0a or
  112.       0x0b, it was created by Pak.
  113.  
  114.     ARC6
  115.       Similar to ARC, but if the second byte of the header is 0x14 or
  116.       higher, it was created by Arc version 6 or higher.
  117.  
  118.    SFX*
  119.       All of the SFX files start with a small decompressor. Seek past
  120.       the decompressor and repeat the above checks.
  121.    -------------------------------------------------------------------- */
  122.  
  123.  
  124. typedef unsigned char BYTE;
  125.  
  126. #define UNKNOWN 0
  127. #define ARC     1
  128. #define ZOO     2
  129. #define ARJ     3
  130. #define LHARC   4
  131. #define LHA     5
  132. #define ZIP     6
  133. #define PAK     7
  134. #define ARC6    8
  135. #define SFXARC  9
  136. #define SFXARJ  10
  137. #define SFXLHARC 11
  138. #define SFXLHA  12
  139. #define SFXZIP  13
  140. #define SFXARC6 14
  141. #define SFXPAK  15
  142. #define EXE     16
  143.  
  144. int WhichArc(char *pName)
  145. {
  146.    FILE  *fp;
  147.    BYTE  header[128];
  148.    int   c, i, n;
  149.  
  150.     memset(header, 0, sizeof(header));
  151.     fp = fopen(pName, "rb");
  152.     if (fp == NULL)
  153.          return -1;     /* error opening file */
  154.     n = fread(header, sizeof(BYTE), sizeof(header) - sizeof(BYTE), fp);
  155.     fclose(fp);
  156.